import 'package:flutter/material.dart';
import 'package:super_study_language_tools/model/model_srt_span.dart';
import 'package:super_study_language_tools/tools/tools_subtitle.dart';

class WidgetSrtInfo extends StatefulWidget {
  WidgetSrtInfo({super.key, required this.srtSpan, required this.onPressed});

  ModelSrtSpan srtSpan;

  final ValueChanged<int> onPressed;

  @override
  State<WidgetSrtInfo> createState() => _WidgetSrtInfoState();
}

class _WidgetSrtInfoState extends State<WidgetSrtInfo> {
  bool _pressed = false;
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTapDown: _handleTapDown,
      onTapUp: _handleTapUp,
      onTap: _handleTap,
      onTapCancel: _handleTapCacel,
      child: Container(
        padding: EdgeInsets.all(10),
        width: 300,
        height: 80,
        color: _pressed ? Colors.lightBlueAccent : Colors.grey[300],
        child: Row(children: [
          Container(
            width: 280,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Text("${widget.srtSpan.id}  "),
                    Text(
                      "${ToolsSubtitle.toHHmmss(widget.srtSpan.startTime)}-${ToolsSubtitle.toHHmmss(widget.srtSpan.endTime)}",
                      textAlign: TextAlign.left,
                    ),
                  ],
                ),
                Text(
                  "${widget.srtSpan.content}",
                  softWrap: true,
                  textAlign: TextAlign.left,
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(fontSize: 12),
                )
              ],
            ),
          )
        ]),
      ),
    );
  }

  void _handleTapDown(TapDownDetails details) {
    setState(() {
      _pressed = true;
    });
  }

  void _handleTapUp(TapUpDetails details) {
    _pressed = false;
    setState(() {});
  }

  void _handleTap() {
    widget.onPressed(widget.srtSpan.id);
  }

  void _handleTapCacel() {
    _pressed = false;
    setState(() {});
  }
}
